#include <array>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "ourhdr.h"

using std::cout;
using std::cin;
using std::cerr;
using std::endl;

Screen::Screen() {
	clear();
}

void Screen::clear(){
	for(int j = 0; j < Pixel::max_col+2; j++){
		m_pixels[0][j] = '0';
		m_pixels[Pixel::max_row+1][j] = '0';
	}
	for(int i = 1; i < Pixel::max_row+1; i++){
		m_pixels[i][0] = '0';
		m_pixels[i][Pixel::max_col+1] = '0';
		for(int j = 1; j < Pixel::max_col+1; j++){
			m_pixels[i][j] = ' ';
		}
	}
	for(int i = Pixel::max_row+2; i < Pixel::max_row+4; i++){
		for(int j = 0; j < Pixel::max_col+2; j++)
			m_pixels[i][j] = ' ';
	}
}

void Screen::show() const{
	system("clear");
	for(int i = 0 ; i < Pixel::max_row+4; i++){
		for(int j = 0 ; j < Pixel::max_col+2; j++){
			cout  << m_pixels[i][j];
		}
		cout << endl;
	}
	cout << std::flush;
}

void Screen::setWords(int line, const char* str){
	if(line <= 0 || line > Pixel::max_row) return;
	if(strlen(str) > Pixel::max_col) return;

	strncpy(m_pixels[line] + Pixel::max_col/2 - strlen(str)/2, str, strlen(str));
}

void Screen::setInfo(const char *str){
	strncpy(m_pixels[Pixel::max_row+3] + Pixel::max_col/2 - strlen(str)/2, str, strlen(str));
}

void Screen::setPixel(unsigned row, unsigned col, char c){
	m_pixels[1+row][1+col] = c;
}

char Screen::getPixel(unsigned row, unsigned col) const{
	return m_pixels[1+row][1+col];
}
